package com.ftg.learn.chapter04;

/**
 * 斐波那契数列
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/5/27 14:37
 */

public class FBNQ {

    public static void main(String[] args) {
//        printFBNQ(4);
        System.out.println(fibonacci(4));
//        int[] a1=printFBNQ1(3);
    }
    public static void printFBNQ(int count){
        long start=1;
        long second=1;
        System.out.println(start+'\t');
        System.out.println(second+'\t');
        int index=2;
        while (index++<count){
            long t=start+second;
            System.out.print(start+second+'\t');
            start=second;
            second=t;
        }
    }

    public static void printFBNQ1(int count){
        int[] arr=new int[count];
        arr[0]=1;
        arr[1]=1;
        for(int i=2;i<count;i++){
            arr[1]=arr[i-1]+arr[i-2];
        }
    }
    /**
     * 递归
     */
    public static int fibonacci(int a){
        int num=0;
        if(a==1||a==2){
            num=1;
            return num;
        }else {
            return fibonacci(a - 1) + fibonacci(a - 2);
        }
    }
}
